import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; // 新增导入
import 'routes.dart';
import 'screens/auth/login_screen.dart';
import 'screens/home/home_screen.dart';
import 'services/auth_service.dart';

class WmsApp extends StatelessWidget {
  const WmsApp({super.key});

  @override
  Widget build(BuildContext context) {
    // 初始化屏幕适配（确保在MaterialApp之前调用）
    ScreenUtil.init(context);
    
    return MaterialApp(
      title: 'WMS',
      theme: ThemeData(
        primarySwatch: Colors.green,
        appBarTheme: AppBarTheme(
          elevation: 0,
          centerTitle: true,
          // 将固定字体大小改为自适应大小
          titleTextStyle: TextStyle(
            fontSize: ScreenUtil().setSp(20), // 替换原有的fontSize: 20
            fontWeight: FontWeight.bold,
            color: Colors.white,
          ),
        ),
      ),
      home: Consumer<AuthService>(
        builder: (context, auth, child) {
          print('isAuthenticated---${auth.isAuthenticated}');
          return auth.isAuthenticated ? const HomeScreen() : const LoginScreen();
        },
      ),
      onGenerateRoute: AppRoutes.generateRoute,
    );
  }
}
    